package easy;

import java.util.Arrays;

public class Solution_1984 {

    public int minimumDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int min = Integer.MAX_VALUE;
        for (int i = 0, j = i + k - 1; j < nums.length; i++, j++) {
            min = Math.min(min, nums[j] - nums[i]);
        }
        return min;
    }

    public static void main(String[] args) {
        Solution_1984 model = new Solution_1984();
        System.out.println(model.minimumDifference(new int[]{90}, 1));
        System.out.println(model.minimumDifference(new int[]{9, 4, 1, 7}, 2));
    }
}
